<?php

class Message_Controller_Browse_Ajax_Menu_Inbox extends Nuo_Controller
{
	function execute($request)
	{
		$table = Nuo::getTable('message');

		$itemTable = Nuo::getT('message_item');

		$viewer = Nuo::getUser();

		$select = $table -> select() 
		-> from(array('m' => $table -> getName())) 
		-> joinLeft(array('i' => $itemTable), 'i.message_id=m.message_id') 
		-> where('i.receiver_id=?', $viewer -> getItemId()) 
		-> order('i.sended_at DESC');
		
		$select->limit(10);
		
		$items = $table->fetchAll($select);

		return  $this->render(array('items' => $items));
	}

}
